<?php
/**
 * Dao of Customer
 *
 * @author steve
 */


require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class CustomerWishlistDao extends BaseDao{

    protected $_name;

    public function  _setup() {
        $this->_name = $this->prefix() . "customer_wishlists";
        parent::_setup();
    }
    
    public function getWishlistByCustomerId($customerId,$offset,$limit){
    	$select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->join("product_items as pi","pi.id = $this->_name.product_item_id","product_id");
        $select->join("products as p","p.id = pi.product_id and p.is_delete = 0 ","title");
        $select->joinLeft("product_images as pim","pim.item_id = $this->_name.product_item_id and pim.is_delete = 0 and pim.default_item_image=1",array("name","folder"));
        $select->where("$this->_name.customer_id = ?",$customerId);
        $select->where("$this->_name.is_delete = 0");
        $select->order("created DESC");
        
        //$select->limit($limit,$offset);
        
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }
    
    public function getWishListTotalNum($customerId){
    	$select = $this->db_r->select();
        $select->from($this->_name,"count(*)");
        $select->join("product_items as pi","pi.id = $this->_name.product_item_id","");
        $select->join("products as p","p.id = pi.product_id and p.is_delete = 0 ","");
      //  $select->joinLeft("product_images as pim","pim.item_id = $this->_name.product_item_id and pim.is_delete = 0 and pim.default_item_image=1",array("name","folder"));
        $select->where("$this->_name.customer_id = ?",$customerId);
        $select->where("$this->_name.is_delete = 0");
      //  $select->order("created DESC");
        $sql = $select->__toString();
        $result = $this->db_r->fetchOne($sql);
        return $result;
    }
}